/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-08-01
 * Time: 14:44
 */
class Counter{
    public int count = 0;
    public void increase() {
        synchronized (this) {
            count++;
        }
    }
}
public class Test {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Thread a = new Thread(() -> {
                System.out.print("A");
            });
            Thread b = new Thread(() -> {
                System.out.print("B");
            });
            Thread c = new Thread(() -> {
                System.out.print("C");
            });

            a.start();
            a.join();

            b.start();
            b.join();

            c.start();
            c.join();

            System.out.println();
        }
    }
    public static void main4(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                counter.increase();
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                counter.increase();
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(counter.count);
    }
    public static void main3(String[] args) throws InterruptedException {
        for(int i = 0; i < 20; i++){
            int j = i;
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(j);
                    //System.out.println(Thread.currentThread().getName());
                }
            });
            thread.start();
            thread.join();
        }
        System.out.println("ok");
    }
    public static void main2(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("1");
            }
        });
        t.start();
        System.out.println("2");
    }

    public static void main1(String[] args) {
        Thread c = new Thread(() -> {
            System.out.println(Thread.currentThread().getName()+" ");
        },"c");

        Thread b = new Thread(() -> {
            try {
                c.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+" ");
        },"b");

        Thread a = new Thread(() -> {
            try {
                b.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
        },"a");
        a.start();
        b.start();
        c.start();
    }
}
